package com.peng.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

@Service
public class MailService {
    @Autowired
    JavaMailSenderImpl javaMailSender;
    public void send(){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("你好呀");
        message.setText("Hello World");
        message.setTo("2719476230@qq.com");
        message.setFrom("2719476230@qq.com");
        javaMailSender.send(message);
    }
    @Async
    public void send2() throws MessagingException {
        MimeMessage message = javaMailSender.createMimeMessage();
        MimeMessageHelper helper=new MimeMessageHelper(message,true);
        helper.setSubject("你好呀");
        helper.setText("<p style='color:red'>欢迎来到我的世界</p>",true);
        helper.addAttachment("1.jpg",new File("C:\\Users\\dell\\Pictures\\Saved Pictures\\small104352ql9tO1632105832.jpg"));
        helper.setTo("2719476230@qq.com");
        helper.setFrom("2719476230@qq.com");
        javaMailSender.send(message);
    }
}
